package cn.maihe.elg.operation.service.ConfigurationCenter.service;

import cn.maihe.elg.operation.service.ConfigurationCenter.config.CenterConfig;
import cn.maihe.elg.operation.service.ConfigurationCenter.dto.CofigureAllDto;
import cn.maihe.elg.operation.service.ConfigurationCenter.dto.ConfigureDto;
import cn.maihe.elg.operation.service.ConfigurationCenter.mapper.ConfigureMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Slf4j
@Service
@Transactional
public class ConfigureServiceImpl implements ConfigureService {
    @Autowired
    private ConfigureMapper configureMapper;

    @Override
    public PageInfo<ConfigureDto> queryConfigure(Integer pageNum, Integer pageSize) {
        //分页查询
        log.info("分页查询配置, pageNum={}, pageSize={}", pageNum, pageSize);        // 启动分页插件，设置当前页码为1，每页显示10条记录
        PageHelper.startPage(1, 10);
        // 查询数据
        List<ConfigureDto> list = configureMapper.queryConfigure();
        // 获取分页结果
        PageInfo<ConfigureDto> pageInfo = new PageInfo<>(list);
        log.info("分页结果：{}", pageInfo);
        //返回结果
        return pageInfo;
    }

    /**
     * 根据平台名称获取配置信息
     *
     * @param platformName 平台名称
     * @return 对应平台的配置信息对象
     */
    @Override
    public CofigureAllDto getConfigByPlatformName(String platformName) {
        return configureMapper.findConfigJsonBySysName(platformName);
    }

    /**
     * 更新指定平台的配置状态
     *
     * @param sysplatformName
     * @param useFlag
     * @return
     */
    @Override
    public int updateConfigStatus(String sysplatformName, Integer useFlag, String LastModifiedBy) {
        return configureMapper.updateConfigStatus(sysplatformName, useFlag, LastModifiedBy);
    }

    @Override
    public int addConfigure(CenterConfig.CenterInfo centerInfo, String createdBy) {
        return configureMapper.addConfigure(centerInfo, createdBy);

    }



}
